package com.artisan.provider.service.impl;

import com.artisan.provider.domain.ZgOrder;
import com.artisan.provider.dto.ZgOrderDto;
import com.artisan.provider.mapper.ZgOrderMapper;
import com.artisan.provider.service.ZgOrderService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ZgOrderServiceImpl implements ZgOrderService {

    @Autowired
    ZgOrderMapper zgOrderMapper;

    @Override
    public List<ZgOrder> findAll(ZgOrderDto zgOrderDto, int page, int limit) {
        if(page > 0 && limit > 0){
            PageHelper.startPage(page,limit);
        }
        return zgOrderMapper.findAll(zgOrderDto);
    }

    @Override
    public int zgOrderAdd(ZgOrder zgOrder) {
        int i = 0;
        try {
           return zgOrderMapper.insertSelective(zgOrder);
        }catch (Exception e){
            return i;
        }

    }

    @Override
    public int zgOrderUpdate(ZgOrder zgOrder) {
        int i = 0;
        try {
            return zgOrderMapper.updateByPrimaryKeySelective(zgOrder);
        }catch (Exception e){
            return i;
        }
    }

    @Override
    public int zgOrderDelete(int id) {
        return zgOrderMapper.deleteByPrimaryKey(id);
    }
}
